<template>
  <span id="timer" class="color-ff3" >{{ timeAll }}</span>
</template>
<script>
  export default {
    props: ['consumeTime', 'payTime'],
    data () {
      return {
        timeAll: '',
        t: 0
      }
    },

    methods: {
      init () {
        let t = this.consumeTime * 60000 - (Date.now() - this.payTime)
        this.t = parseInt(t / 1000)
        this.timeNum()
      },
      // 倒计时？
      timeNum() {
        let timer
        if (this.t) {
          var h = 0;
          var m = 0;
          var s = 0;
          timer = setInterval(() => {
            this.t--
            if (this.t > 0) {
              h = parseInt(this.t / 3600);
              m = parseInt(this.t / 60 % 60);
              s = parseInt(this.t % 60);
              if (m < 10) {
                m = '0' + m
              }
              if (s < 10) {
                s = '0' + s
              }
              this.timeAll = h + '时' + m + '分' + s + '秒';
              if (h < 1) {
                this.timeAll = m + '分' + s + '秒';
              }
              // console.log(this.timeAll);
            } else {
              this.$emit('changeState')
              clearTimeout(timer)
            }
          }, 1000)
        }
      }
    },

    created () {
    },

    mounted () {
      this.init()
      console.log(this.payTime);
    }
  }
</script>
